<div class="shadow">
  <br/>
  <fieldset id="agrupacion">
    <legend>Patrimonio</legend>
    <div>

      <% form_tag url_for(:action=>"update_table_heritage", :html => { :multipart => true}),{:id =>"cultural_heritage_form_transfer_search"} do -%>
        <p class="two-col"><label></label><%= text_field_tag "search_name" %><input class="button" name="Buscar" value="Buscar" id="cultures_search" type="submit" /><span id="loading_search" style="display:none"></span>
        </p>
      <% end %>
      <br/>
      <br id="search_name"></br>
      <%= form_for(@cultural_heritage_transfer, :html=>{:onsubmit => "return validate(this);" }) do |f| %>
      <%= render :partial=>"table_1" %>
      </div>
    </fieldset>


    <% if @cultural_heritage_transfer.errors.any? %>
      <div id="error_explanation">
        <h2><%= pluralize(@cultural_heritage_transfer.errors.count, "error") %> prohibited this cultural_heritage_transfer from being saved:</h2>

        <ul>
          <% @cultural_heritage_transfer.errors.full_messages.each do |msg| %>
            <li><%= msg %></li>
          <% end %>
        </ul>
      </div>
    <% end %>

    <fieldset id="agrupacion">
      <legend>Detalle del Traslado</legend>

      <fieldset class="column-left">
        <div class="field">
          <label>Fecha Inicio</label><br />
          <%= f.datepicker 'startdate'%>
        </div>

<%#*para combobox%>
        <div class="field" id="cultural_heritage_transfer_origin">
          <p><label>Institución Cultural de Origen</label><br /><%= f.select :origin, @origins.collect { |t| [t.name,t.id]}, {:include_blank=>"Seleccione"}, {:class => 'combobox'} %> </p>
        </div>

      </fieldset>

      <fieldset class="column-rigth">


        <div class="field">
          <label>Fecha Fin</label><br />
          <%= f.datepicker 'enddate'%>

        </div>

        <div class="field">
          <p><label id="cultural_heritage_transfer_destiny">Institución Cultural de Destino</label><br /><%= f.select :destiny,@destinies.collect { |t| [t.name,t.id]}, {:include_blank=>"Seleccione"}, {:class => 'combobox'} %> </p>
        </div>
      </fieldset>

      <div class="field">
        <label>Descripcion</label><br />
        <%= f.text_area :description %>
      </div>


      <div class="field">
        <p><label id="cultural_heritage_transfer_responsable">Responsable</label><br /><%= f.select :responsable,@responsable.collect { |t| [t.name << ' ' << t.lastname,t.id]}, {:include_blank=>"Seleccione"}, {:class => 'combobox'} %> </p>
      </div>

      <div class="actions">
        <%= f.submit "Guardar" %>
      </div>
    <% end %>
  </fieldset>
</div>

<script type="text/javascript">
  // form validation function //
  function validate(form) {
    //input
    //select
   /* var nationalRegistrationCode = form.cultural_heritage_cultural_heritage_nationalRegistrationCode.value;
    //input number*/
    var origin = form.cultural_heritage_transfer_origin.value;
    //textarea
    var destiny = form.cultural_heritage_transfer_destiny.value;
    var responsable = form.cultural_heritage_transfer_responsable.value;
    var startdate = form.cultural_heritage_transfer_startdate.value;
    var enddate = form.cultural_heritage_transfer_enddate.value;
    var currentdate = new Date();
    
    var checkboxes = document.getElementsByName("lheritage[]");

    var cont = 0;

    for (var x=0; x < checkboxes.length; x++) {
      if (checkboxes[x].checked) {
        cont = cont + 1;
      }
    }

    if(cont == 0) {
      inlineMsg('search_name','Debe seleccionar al menos un patrimonio para el Traslado.',3);
      return false;
    }
    /*var period = form.cultural_heritage_cultural_heritage_period.value;*/
    //var email = form.email.value;

    /*Para un input*/
   /* if(nationalRegistrationCode == "") {
      inlineMsg('cultural_heritage_cultural_heritage_nationalRegistrationCode','Debe ingresar un Codigo de Registro Nacional para el Patrimonio Cultural.',3);
      return false;
    }
    if(!nationalRegistrationCode.match(nameRegex)) {
      inlineMsg('nationalRegistrationCode','Debe de ingresar un Codigo de Registro Nacional válido.',3);
      return false;
    }
    if(name == "") {
      inlineMsg('cultural_heritage_cultural_heritage_name','Debe ingresar un nombre para el Patrimonio Cultural.',3);
      return false;
    }
    if(!name.match(nameRegex)) {
      inlineMsg('name','Debe de ingresar un nombre válido.',3);
      return false;
    }*/
    /*Para un select*/    
    if (!checkDate(startdate)){
      inlineMsg('cultural_heritage_transfer_startdate',errorMsg,3);
      return false;
    }
    if(_parseDate(startdate) <= currentdate) {
      inlineMsg('cultural_heritage_transfer_startdate','Debe fecha de inicio debe ser posterior a la de hoy',3);
      return false;
    }
    if (!checkDate(enddate)){
      inlineMsg('cultural_heritage_transfer_enddate',errorMsg,3);
      return false;
    }
    if(_parseDate(startdate) > _parseDate(enddate)) {
      inlineMsg('cultural_heritage_transfer_enddate','Debe fecha de fin debe ser mayor a la de inicio',3);
      return false;
    }

    if(origin == "") {
      inlineMsg('cultural_heritage_transfer_origin','Debe seleccionar una Institución Cultural Origen para el Traslado.',3);
      return false;
    }
    if(destiny == "") {
      inlineMsg('cultural_heritage_transfer_destiny','Debe seleccionar una Institución Cultural Destino para el Traslado.',3);
      return false;
    }
    if(responsable == "") {
      inlineMsg('cultural_heritage_transfer_responsable','Debe seleccionar un Responsable para el Traslado.',6);
      return false;
    }
    
    <%#*if(enddate == "") {%>
      <%#*inlineMsg('cultural_heritage_transfer_end','Debe seleccionar un Responsable para el Traslado.',3);%>
      <%#*return false;%>
    <%#*}%>
    /*
    if(email == "") {
      inlineMsg('email','<strong>Error</strong><br />You must enter your email.',3);
      return false;
    }
    if(!email.match(emailRegex)) {
      inlineMsg('email','<strong>Error</strong><br />You have entered an invalid email.',3);
      return false;
    }
    */
  }
</script>